package com.lanchetech.service.impl;


import com.lanchetech.service.InviteCodeService;
import org.hashids.Hashids;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class InviteCodeServiceImpl implements InviteCodeService {
    @Value("${customer.hashid.salt}")
    private String salt;

    @Override
    public String generateInviteCode(Long userId) {
        Hashids hashids = new Hashids(salt, 6);
        return hashids.encode(userId);
    }

    @Override
    public Long decodeInviteCode(String inviteCode) {
        Hashids hashids = new Hashids(salt, 6);
        return hashids.decode(inviteCode)[0];
    }
}
